package com.bicon.botu.finance.wallet.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.bicon.botu.finance.wallet.entity.PaymentCenter;
import com.bicon.botu.finance.wallet.service.PaymentCenterService;
import com.bicon.botu.core.base.common.Constants;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 支付中心 前端控制器
 * </p>
 *
 * @author tandk
 * @since 2018-05-17
 */
@RestController
@RequestMapping("/V1.0.0/controller/payment-center")
public class PaymentCenterController extends BaseController {

    @Autowired
    private PaymentCenterService paymentCenterService;

    /**
     * 修改支付信息开启状态
     *
     * @param id          支付信息id
     * @param whetherShow 是否展示（0：展示，1：不展示）
     * @return
     */
    @RequestMapping(value = "/update")
    public BaseResult update(String id, int whetherShow) {
        if (whetherShow != 0 && whetherShow != 1) {
            return sendResult400();
        }
        PaymentCenter paymentCenter = new PaymentCenter();
        paymentCenter.preUpdate();
        paymentCenter.setId(id);
        paymentCenter.setWhetherShow(whetherShow);
        return paymentCenter.updateById() ? sendResult200() : sendResult400();
    }

    /**
     * 查询所有支付信息
     *
     * @return
     */
    @RequestMapping(value = "/list")
    public BaseResult list() {
        List<PaymentCenter> paymentCenters = new PaymentCenter().selectList(new EntityWrapper<PaymentCenter>().eq("logic_delete", Constants.DEL_LOGIC_NORMAL).orderBy("sort", false));
        return paymentCenters.size() > 0 ? sendResult200(paymentCenters) : sendResult200();
    }

    /**
     * 修改支付信息排序
     *
     * @param id   支付信息id
     * @param sort 序号
     * @return
     */
    @RequestMapping(value = "/sort")
    public BaseResult sort(String id, int sort) {
        PaymentCenter paymentCenter = new PaymentCenter();
        paymentCenter.preUpdate();
        paymentCenter.setId(id);
        paymentCenter.setSort(sort);
        return paymentCenter.updateById() ? sendResult200() : sendResult400();
    }
}
